ass Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) 
    {

        if (root==nullptr)
        {
            return {};
        }
        vector<vector<int>> ans;
        vector<int> temp;
        int levelsize = 1;
        queue<Node*> que;
        que.push(root);
        Node* cur = root;

        while(!que.empty())
        {
            if (levelsize) 
            {
                levelsize--;
                cur = que.front();
                que.pop();
                temp.push_back(cur->val);
                for (auto& i : cur->children)
                {
                    que.push(i);
                }
            }
            else
            {
                levelsize = que.size();
                ans.push_back(temp);
                temp.clear();
            }
        }

            ans.push_back(temp);
            return ans;
    }


};<Paste>
